<template>
  <div class="main-body">
    <div class="header flex-body">
      <div class="logo">
        <img :src="`${programInfo.logoUrl ? programInfo.logoUrl : logo}`" alt="logo" />
      </div>
      <div class="tips txt-ellipsis">{{ menuTitle }}</div>
      <div class="timer clearfix">
        <dl class="week">
          <dt>{{ week }}</dt>
          <dd>{{ date }}</dd>
        </dl>
        <div class="time">{{ time }}</div>
      </div>
    </div>
    <div :class="['main']" :style="{ backgroundImage: drak ? '' : `url(${programInfo.backgroundUrl})` }">
      <transition>
        <keep-alive>
          <component :is="component" :key="`${component}-${programId}`" :programId="programId" @setComponent="setComponent" />
        </keep-alive>
      </transition>
    </div>
    <base-footer @setComponent="setComponent" />
  </div>
</template>

<script>
import { getGuidesInfo } from '@/api';
import { getSearchParams, weekDict } from '@/utils';
import dayjs from 'dayjs';
import HomePage from '@/views/home/index';
import info1 from '@/views/details/index.vue'; // 图文详情
import info2 from '@/views/department/index.vue'; // 二级分类A-科室介绍
import info3 from '@/views/classify/index.vue'; // 二级分类B-流程查询
import info4 from '@/views/location/index.vue'; // 位置查询
import info5 from '@/views/docter/index.vue'; // 人员介绍
import info6 from '@/views/building/index.vue'; // 楼宇分布
import info7 from '@/views/notice/index.vue'; // 通知公告
import baseFooter from '@/components/baseFooter';
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  components: {
    HomePage,
    info1,
    info2,
    info3,
    info4,
    info5,
    info6,
    info7,
    baseFooter
  },
  data() {
    return {
      week: '星期二',
      date: '2025-7-19',
      time: '09:46',
      deviceInfo: {},
      programInfo: {},
      logo: require('@/assets/images/logo.png'),
      component: 'HomePage',
      menuTitle: ''
    };
  },
  watch: {
    component(val) {
      if (val !== 'HomePage') {
        this.$store.commit('SET_FOOTER', true);
      } else {
        this.$store.commit('SET_SHOW', false);
        this.$store.commit('SET_FOOTER', false);
      }
    }
  },
  computed: {
    programId() {
      return this.$store.getters.program;
    },
    show() {
      return this.$store.getters.show;
    },
    drak() {
      return ['info1', 'info2', 'info6'].includes(this.component);
    }
  },
  created() {
    window.setDate = this.setDates; // 设置日期
    window.getDeviceInfoCallBack = this.getDeviceInfoCallBacks;
  },
  beforeDestroy() {
    window.setDate = null;
    window.getDeviceInfoCallBack = null;
  },
  mounted() {
    this.$AndroidSdk.deviceInfoAction();
    let week = dayjs().format('ddd');
    this.week = weekDict[week];
    this.date = dayjs().format('YYYY年MM月DD日');
    this.time = dayjs().format('HH:mm');
    // getDeviceInfoCallBack({"coordinateX":"12943048.759621853","coordinateY":"4852142.1272678","deviceId":"beb259a857fb492098f7e913c4afc1cc","deviceType":24,"floorId":"","hospitalId":"4e66fabafd944e458dc259ce890c31f3","location":"11111111","serverIp":"192.168.30.167"})
  },
  methods: {
    setDates(week, time, date) {
      this.week = week;
      this.time = time;
      this.date = date;
    },
    // 获取设备信息回调
    getDeviceInfoCallBacks(obj) {
      this.$AndroidSdk.writeLog('设备基本信息回调--->' + JSON.stringify(obj));
      const guidesId = getSearchParams('guidesId');
      if (guidesId.trim() !== '') {
        this.getProgramInfos(guidesId);
      }
    },
    getProgramInfos(guidesId) {
      getGuidesInfo({
        id: guidesId
      }).then((res) => {
        if (res.status == 0) {
          const { backgroundUrl = '', listProgram = [], logoUrl = '' } = res.data || {};
          this.$store.commit('SET_NAV', listProgram);
          this.programInfo = {
            backgroundUrl,
            logoUrl
          };
        }
      });
    },
    setComponent(row) {
      if (row.type === 'system') {
        if (row.mode === 'home' || !this.show) {
          this.menuTitle = '';
          this.component = 'HomePage';
          this.$store.commit('SET_FOOTER', false);
        } else {
          this.$store.commit('SET_SHOW', false);
        }
      } else {
        this.$store.commit('SET_PROGRAM', row.programId);
        this.component = row.component;
        this.menuTitle = row.programName || '';
      }
    }
  }
};
</script>
